package com.itheima.health.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.service.OrderSettingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class CleanOrderSettingJob {
    private static final Logger log = LoggerFactory.getLogger(CleanImgJob.class);
    @Reference
    private OrderSettingService orderSettingService;

    @Scheduled(cron = "0 0 2 L * ?")
    public void cleanOrderSetting() {
        //1.获取当月第一天
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //1.1设定当前时间为本月一号
        calendar.set(Calendar.DAY_OF_MONTH, 1);

        Date date = calendar.getTime();
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = dateFormat.format(date);

        //2.调用Service
        orderSettingService.cleanOrderSetting(dateStr);

        log.info(dateStr+"之前的预约信息已被自动清理！");
    }
}
